//
//  WCReceiveDelegate.swift
//  NJU QR WatchKit Extension
//
//  Created by 许煜恒 on 8/16.
//

import Foundation
import WatchConnectivity
import SwiftUI

class WCReceiveDelegate: NSObject,WCSessionDelegate {
    //Used on watchOS
    
    @AppStorage("login_cookie")
    private var login_cookie:String?
    
    func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
        return
    }
    

    
    func session(_ session: WCSession, didReceiveUserInfo userInfo: [String : Any] = [:]) {
        login_cookie=userInfo["login_cookie"]! as? String
    }
    
    func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
        return
    }
}

var didTransmission:Bool=false
let delegate=WCReceiveDelegate()
func doTransmission(){
    if WCSession.isSupported() && didTransmission==false{
        let session=WCSession.default
        session.delegate=delegate
        session.activate()
        didTransmission=true
    }
}
